<template>
  <div
    class="models__wrappper border-trasnsparent"
    v-click-outside="() => handleModelShow(false)"
  >
    <el-popover popper-class="ai_models_wrappper_pop" width="380" placement="top-start" trigger="manual" visibleArrow v-model="isAgentNew">
      <div class="popper-content" v-click-outside="() => setIsAgentNew()">
        <svg-icon icon-class="close" class="close-btn fs-16" @click="setIsAgentNew"></svg-icon>
        <div class="content-title">点击这里可以选择模型或AI应用</div>
        <ul class="mt-20">
          <li>
            <svg-icon icon-class="deepseek_logo" class="fs-24"></svg-icon>
            <span>DeepSeek</span>
          </li>
          <li>
            <svg-icon icon-class="qw_logo" class="fs-24"></svg-icon>
            <span>通义千问</span>
          </li>
          <li>
            <svg-icon icon-class="zhipu_logo" class="fs-24"></svg-icon>
            <span>清华智普</span>
          </li>
        </ul>
        <ul class="last mb-20">
          <li>
            <svg-icon icon-class="xhs_logo" class="fs-24"></svg-icon>
            <span>小红书文案</span>
          </li>
          <li>
            <svg-icon icon-class="tiktop_logo" class="fs-24"></svg-icon>
            <span>视频文案</span>
          </li>
        </ul>
        <div class="popper-footer">
          <el-button @click="setIsAgentNew">我知道了</el-button>
          <el-button type="primary" @click="handleRemove">立即体验</el-button>
        </div>
      </div>
      <div slot="reference" class="current__item" @click.stop="handleModelShow('models')">
        <img
          v-if="currentModel && currentModel.icon"
          :src="currentModel.icon"
          class="fs-16 flex-shrink-0"
          width="16"
          height="16"
        />
        <svg-icon
          v-else
          :icon-class="currentModel && formatModelTypeIcon(currentModel.model) || ''"
          class="fs-16 flex-shrink-0"
        ></svg-icon>
        <span class="model__name" v-if="currentModel">{{ currentModel.name }}</span>
        <svg-icon icon-class="right-btn" class="right-btn flex-shrink-0 fs-14 ml-4"></svg-icon>
      </div>
    </el-popover>
    <model-pop />
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { formatModelTypeIcon } from '@/utils'
import ModelPop from './pop/index.vue'
export default {
  name: 'ChatModels',
  inject: ['setIsAgentNew'],
  components: {
    ModelPop
  },
  data () {
    return {
    }
  },
  props: {
    isAgentNew: {
      type: Boolean,
      default: () => false
    }
  },
  computed: {
    ...mapGetters(['chatStore']),
    isChatDocument () { return this.chatStore.docSummarize.status !== '' },
    currentModel () {
      return this.isChatDocument ? this.chatStore.currentDocumentModel : this.chatStore.currentModel
    }
  },
  methods: {
    formatModelTypeIcon,
    handleModelShow (val) {
      if (this.chatStore.showModels) {
        this.$store.dispatch('chat/setChatStore', { showModels: false })
        return
      }
      this.setIsAgentNew()
      this.$store.dispatch('chat/setChatStore', { showModels: val })
    },
    handleRemove () {
      this.$xz('HtmlClickReport', { ReportID: 7617 })
      this.setIsAgentNew()
      this.handleModelShow('models')
    }
  }
}
</script>

<style lang="scss" scoped>
.models__wrappper {
  position: relative;
  flex: 0 0 auto;
  box-sizing: border-box;
  cursor: pointer;
  background: rgba(255,255,255,0.1);
  border-radius: 34px;
  &:hover {
    background: rgba(255,255,255,0.2);
  }
}
.model__name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex: 1 1 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.current__item {
  position: relative;
  font-size: $font-size-base;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  padding: 5px 10px;
  gap: 5px;
  height: 26px;
  width: fit-cotent;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-sizing: border-box;
  .right-btn {
    transform: rotate(90deg);
    position: relative;
    top: 1px;
  }
  &:hover {
    color: #ffffff;
  }
}
.popper-content {
  .close-btn {
    color: #393D59;
    position: absolute;
    top: 13px;
    right: 13px;
    &:hover {
      color: #fff;
    }
  }
  .content-title {
    font-weight: bold;
    font-size: 16px;
    color: #FFFFFF;
    line-height: 24px;
  }
  ul {
    display: flex;
    gap: 10px;
    font-size: 12px;
    li {
      width: 103px;
      height: 40px;
      background: rgba(255,255,255,0.1);
      border-radius: 5px;
      display: flex;
      gap: 6px;
      justify-content: center;
      align-items: center;
    }
    &.last {
      margin-top: 10px;
      li {
        width: 160px;
      }
    }
  }
  .popper-footer {
    display: flex;
    justify-content: center;
    .el-button {
      width: 116px;
      height: 34px;
      border-radius: 5px;
      padding: 0;
      border: 0;
      &:hover {
        background: rgba(255,255,255,0.2);
      }
    }
    .el-button + .el-button {
      margin-left: 14px;
      &:hover {
        border: 0;
        background: #3444e1;
      }
    }
  }
}
</style>
<style lang="scss">
.ai_models_wrappper_pop {
  // width: 360px;
  // height: 228px;
  box-sizing: border-box;
  padding: 20px 25px;
  background: linear-gradient( 180deg, #1D1F28 0%, #393D59 100%);
  box-shadow: 0px 0px 15px 0px rgba(0,0,0,0.1);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.2);
  margin-bottom: 16px !important;

  &::after {
    position: absolute;
    bottom: -27px;
    left: 50px;
    content: "";
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 14px 10px; /* 可以根据需要调整大小 */
    border-color: #393D59 transparent transparent transparent ; /* 上边框透明，其他透过 */
  }
  &::before {
    position: absolute;
    bottom: -28px;
    left: 50px;
    content: "";
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 14px 10px; /* 可以根据需要调整大小 */
    border-color: rgba(255,255,255,0.2) transparent transparent transparent ; /* 上边框透明，其他透过 */
  }
}
</style>
